package com.ibeeking.found.file.rest.service.office.mappers;

import com.ibeeking.found.file.rest.service.office.entities.PermissionEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
@Primary
public class PermissionsMapper extends AbstractMapper<PermissionEntity, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.Permission> {
    @Resource
    private ModelMapper mapper;

    public PermissionsMapper() {
        super(com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.Permission.class);
    }

    @PostConstruct
    public void configure() {  // configure the permission mapper
        mapper.createTypeMap(PermissionEntity.class, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.Permission.class)  // create the type map
                .setPostConverter(modelConverter());  // and apply the post converter to it
    }

    @Override
    void handleSpecificFields(PermissionEntity source, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.Permission destination) {  // handle specific permission fields
//        destination.setReviewGroupEntities(source.getReviewGroupEntities().stream().map(g -> g.getName()).collect(Collectors.toList()));  // set the reviewGroups parameter
//        destination.setCommentGroups(  // set the commentGroups parameter
//                new CommentGroup(
//                        source.getCommentsViewGroupEntities().stream().map(g -> g.getName()).collect(Collectors.toList()),
//                        source.getCommentsEditGroupEntities().stream().map(g -> g.getName()).collect(Collectors.toList()),
//                        source.getCommentsRemoveGroupEntities().stream().map(g -> g.getName()).collect(Collectors.toList())
//                )
//        );
//        destination.setUserInfoGroupEntities(source.getUserInfoGroupEntities().stream().map(g -> g.getName()).collect(Collectors.toList()));
    }
}
